<?php defined('BASEPATH') OR exit('No direct script access allowed');


class ads_model extends WS_model
{

    public function get_ads($filter = array())
    {
        $this->db->from('ads_management');
        $count = (isset($filter['count']) ? TRUE : FALSE);
        $perPage = (isset($filter['per_page']) ? $filter['per_page'] : FALSE);
        $offset = (isset($filter['offset']) ? $filter['offset'] : FALSE);

        if (isset($filter['name']) && $filter['name']) {
            $this->db->like('ad_name', $filter['name']);
        }

        if ($count) {
            return $this->count();
        }

        if ($perPage)
            $this->db->limit($perPage, $offset);
        if(isset($filter['array']))
            return $this->result_array();
        return $this->result();
    }

    public function insert($data)
    {
        $this->db->insert('ads_management', $data);
        return $this->db->insert_id();
    }

    public function update($data, $where)
    {
        $this->db->update('ads_management', $data, $where);
    }

    public function get_ad($id)
    {
        $this->db->from('ads_management');
        $this->db->where('ad_seq_id', $id);
        return $this->row();
    }

    public function delete($id)
    {
        $this->db->delete('ads_management', array('ad_seq_id' => $id));
    }
}